﻿package com.wongoing.sys.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.wongoing.base.BaseServiceImpl;
import com.wongoing.base.PageResult;
import com.wongoing.sys.dao.SysUserRoleDao;
import com.wongoing.sys.model.SysUserRole;
import com.wongoing.sys.model.ext.SysUserRoleEditExt;
import com.wongoing.sys.model.ext.SysUserRoleExt;
import com.wongoing.sys.service.SysUserRoleService;

@Service("sysUserRoleService")
@Transactional
public class SysUserRoleServiceImpl extends BaseServiceImpl<SysUserRole> implements SysUserRoleService {
	private SysUserRoleDao dao;

	@Autowired
	public void setDao(SysUserRoleDao dao) {
		super.setDao(dao);
		this.dao = dao;
	}
	
	/**
	 * 功能说明：获取用户角色列表最终分页数据（页面展示）
	 * 修改说明：
	 * @author zhenglibing,吴兆强
	 * @date 2017年10月13日 下午10:29:45
	 * @param pageResult 分页查询对象，包含查询条件
	 * @return 返回分页查询对象，包含页面数据
	 */
	public PageResult<SysUserRoleExt> getUserRoleConfigListPageResult(PageResult<SysUserRoleExt> pageResult) {
		pageResult.getParam().put("offset", pageResult.getPageSize() * (pageResult.getPageCurrent() - 1));
		pageResult.getParam().put("limit", pageResult.getPageSize());
		if (!"".equals(pageResult.getOrderField())) { pageResult.getParam().put("orderColumn", pageResult.getOrderField()); }
		pageResult.getParam().put("orderTurn", pageResult.getOrderDirection());
		List<SysUserRoleExt> data = this.dao.getUserRoleConfigListByParam(pageResult.getParam());
		pageResult.setList(data);
		int totalSize = this.dao.countOfUserRoleConfigListByParam(pageResult.getParam());
		pageResult.setTotal(totalSize);
		return pageResult;
	}
	
	/**
	 * 功能说明：获取用户角色分配编辑列表最终页面展示数据
	 * 修改说明：
	 * @author zhenglibing,吴兆强
	 * @date 2017年10月13日 下午10:31:23
	 * @param pageResult 分页查询对象，包含查询条件
	 * @return 返回分页查询对象，包含页面数据
	 */
	public PageResult<SysUserRoleEditExt> getUserRoleEditListPageResult(PageResult<SysUserRoleEditExt> pageResult) {
		pageResult.getParam().put("offset", pageResult.getPageSize() * (pageResult.getPageCurrent() - 1));
		pageResult.getParam().put("limit", pageResult.getPageSize());
		if (!"".equals(pageResult.getOrderField())) { pageResult.getParam().put("orderColumn", pageResult.getOrderField()); }
		pageResult.getParam().put("orderTurn", pageResult.getOrderDirection());
		List<SysUserRoleEditExt> data = this.dao.getUserRoleEditListByParam(pageResult.getParam());
		pageResult.setList(data);
		int totalSize = this.countByParam(pageResult.getParam());
		pageResult.setTotal(totalSize);
		return pageResult;
	}
}
